home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / pdclk139.zip / SETTIME.ASM < prev    next >
Assembly Source File  |  1992-05-17  |  6KB  |  283 lines

  1. ;========================================================================
  2.  
  3. ; Copyright (C) 1991 by Jan.Engvald@ldc.lu.se, see file COPYING.
  4.  
  5. ;************************************************************************
  6. ;*        SetTime
  7. ;************************************************************************
  8.  
  9. SetTime     proc    near
  10.         push    cs
  11.         push    cs
  12.         pop    ds
  13.         pop    es
  14.         cld
  15.                         ; convert from network byte
  16.         mov    cx,cTime        ;   order
  17.         xchg    ch,cl
  18.         mov    bx,cTime+2
  19.         xchg    bh,bl
  20.  
  21.         mov    dx,tzoffset+2        ;   and apply time zone
  22.         xchg    dh,dl
  23.         sub    bx,dx
  24.         mov    ax,tzoffset        ;   offset
  25.         xchg    ah,al
  26.         sbb    cx,ax
  27.  
  28.         mov    ax,AlterTime        ; add alter-days
  29.         imul    m6hour
  30.         shl    ax,1
  31.         rcl    dx,1
  32.         shl    ax,1
  33.         rcl    dx,1
  34.         add    bx,ax
  35.         adc    cx,dx
  36.  
  37.         mov    ax,AlterTime+2        ; add alter-time
  38.         mov    dx,AlterTime+4
  39.         add    bx,ax
  40.         adc    cx,dx
  41.  
  42.         mov    si,AlgPtr
  43.         or    si,si            ; any daylight algorithm?
  44.         jnz    DoDls
  45.         jmp    SetNoDls
  46.   DoDls:
  47.         push    bx
  48.         push    cx
  49.         add    si,4
  50.         lodsw                ; from switching time
  51.         imul    m1
  52.         sub    bx,ax
  53.         sbb    cx,dx
  54.  
  55.         call    DateTimeCalc        ; dst start evaluation
  56.  
  57.         cmp    si,offset AlgTab.Apa0    ; four entry part?
  58.         jl    SingleEntry
  59.  
  60.         mov    al,AlgEntryLen
  61.         mul    cNonLeapYear
  62.         add    si,ax
  63.         cmp    si,offset AlgTab.Ais0    ; acyclic entry?
  64.         jb    SingleEntry
  65.  
  66.         cmp    cYear,WARNYEAR
  67.         jb    SingleEntry
  68.  
  69.         mov    MsgTermStop,' '        ; activate warning msg
  70.   SingleEntry:
  71.         mov    bp,cDayOfYear
  72.         lodsw                ; from switching weekday
  73.         cmp    al,SAT
  74.         ja    FromDate
  75.         dec    bp
  76.         cmp    ax,cWday
  77.         jg    CurWeekF
  78.         add    bp,7
  79.   CurWeekF:
  80.         sub    bp,cWday
  81.         add    bp,ax
  82.   FromDate:
  83.         pop    cx
  84.         pop    bx
  85.         push    bx
  86.         push    cx
  87.         lodsw                ; from switching week
  88.  
  89.         push    ax
  90.         lodsw                ; until switching time
  91.         imul    m1
  92.         sub    bx,ax
  93.         sbb    cx,dx
  94.  
  95.         call    DateTimeCalc        ; dst end evaluation
  96.  
  97.         mov    di,cDayOfYear
  98.         pop    dx
  99.  
  100.         lodsw                ; until switching weekday
  101.         cmp    al,SAT
  102.         ja    UntilDate
  103.         dec    di
  104.         cmp    ax,cWday
  105.         jg    CurWeekU
  106.         add    di,7
  107.   CurWeekU:
  108.         sub    di,cWday
  109.         add    di,ax
  110.   UntilDate:
  111.         lodsw                ; until switching week
  112.         test    cNonLeapYear,011b
  113.         jnz    SetNotLeap
  114.         cmp    ax,31+28
  115.         jbe    SetChkLU
  116.         inc    ax
  117.   SetChkLU:
  118.         cmp    dx,31+28
  119.         jbe    SetNotLeap
  120.         inc    dx
  121.   SetNotLeap:
  122.         pop    cx
  123.         pop    bx
  124.         cmp    ax,dx            ; north or south of equator?
  125.         jl    SetSouth
  126.         cmp    dx,bp            ; to do or not to do dls?
  127.         jg    SetNoDls
  128.         jmp    short SetChkUntil
  129.   SetSouth:
  130.         cmp    dx,bp            ; to do or not to do dls?
  131.         jle    DoDLSaving
  132.   SetChkUntil:
  133.         cmp    di,ax
  134.         jge    SetNoDls
  135.   DoDLSaving:
  136.         or    GenFlags,DSTNOW
  137.         lodsw                ; dst advance time
  138.         mov    DstAdvance,ax
  139.         imul    m1
  140.         add    bx,ax
  141.         adc    cx,dx
  142.   SetNoDls:
  143.         call    DateTimeCalc        ; calculate date and time
  144.  
  145.         test    Flagword,DONT_SETTIME    ; did we use alter argument?
  146.         jz    SetPCtime
  147.  
  148.         mov    di,offset msgset
  149.         mov    cx,12
  150.         mov    al,' '
  151.         rep    stosb            ; clear "Clock set to"
  152.         jmp    SkipTimeset
  153.   SetPCtime:
  154.         mov    cx,cYear
  155.         mov    dh,byte ptr cMonth
  156.         mov    dl,byte ptr Cday
  157.         mov    ah,2Bh            ; set date
  158.         int    21h
  159.         or    al,al
  160.         jz    DateOK
  161.         mov    al,5            ; error code 5
  162.         call    terminate
  163.   DateOK:
  164.         mov    ch,byte ptr cHour
  165.         mov    cl,byte ptr cMinute
  166.         mov    dh,byte ptr cSecond
  167.         mov    dl,99
  168.         mov    ah,2Dh            ; set time
  169.         int    21h
  170.         or    al,al
  171.         jz    TimeOK
  172.         mov    al,6            ; error code 6
  173.         call    terminate
  174.   TimeOK:
  175.   SkipTimeset:                    ; edit time display msg
  176.         mov    al,byte ptr cWday
  177.         mul    m6
  178.         add    ax,offset Weekdays
  179.         mov    si,ax
  180.         mov    di,offset msgweek
  181.         mov    cx,3
  182.         rep    movsw            ; copy weekday string
  183.             
  184.         mov    si,offset cYear
  185.         mov    di,offset msgyear
  186.         mov    ch,'-'
  187.         mov    cl,3
  188.         call    PutNums         ; put date
  189.  
  190.         mov    di,offset msghour
  191.         mov    ch,':'
  192.         mov    cl,3
  193.         call    PutNums         ; put time
  194.  
  195.         mov    si,offset RespondingIpNr
  196.         mov    di,offset msgts
  197.         call    PutIpNum        ; put time server IP #
  198.  
  199.         mov    dx,offset msgset
  200.         mov    ah,9
  201.         int    21h            ; display string
  202.  
  203.         ret
  204. SetTime     endp
  205.  
  206.  
  207.  
  208. ;************************************************************************
  209. ;*        DateTimeCalc
  210. ;************************************************************************
  211.  
  212. DateTimeCalc    proc    near
  213.         mov    ax,bx
  214.         mov    dx,cx
  215.         push    si
  216.         push    ax            ; save seconds since
  217.         push    dx            ;   year 1900
  218.  
  219.         mov    si,offset Ytab
  220.         mov    cx,4*64
  221.         call    SearchAndSub        ; find and subtract years
  222.         add    cx,1964
  223.         mov    cYear,cx        ; set year
  224.  
  225.         push    ax            ; reminder still too big
  226.         push    dx            ;   for 16 bits,
  227.         shr    dx,1            ;   have to
  228.         rcr    ax,1            ;   divide by 2
  229.         div    m12hour
  230.         inc    ax
  231.         mov    cDayOfYear,ax        ; set day within year
  232.  
  233.         pop    dx            ; restore seconds within year
  234.         pop    ax
  235.  
  236.         and    cl,011b         ; extract leap year index
  237.         mov    cNonLeapYear,cl
  238.         mov    si,offset Motab
  239.         jnz    NoLeapYear
  240.         mov    si,offset Mltab
  241.   NoLeapYear:
  242.         mov    cx,4*16
  243.         call    SearchAndSub        ; find and subtract month
  244.         inc    cx
  245.         mov    cMonth,cx        ; set month within year
  246.  
  247.         shr    dx,1            ; reminder still too big
  248.         rcr    ax,1            ;   for 16 bits, have to
  249.         rcr    bx,1            ;   divide by 2
  250.         div    m12hour         ; divide by 24hr/2
  251.         inc    ax
  252.         mov    cDay,ax         ; set day within month
  253.  
  254.         mov    ax,dx
  255.         xor    dx,dx
  256.         shl    bx,1            ; recover lost bit
  257.         rcl    ax,1            ;   into reminder
  258.         rcl    dx,1
  259.         div    mhour            ; divide by 3600
  260.         mov    cHour,ax        ; set hour within day
  261.  
  262.         mov    ax,dx
  263.         div    m60b            ; divide by 60
  264.         mov    dl,ah
  265.         xor    dh,dh
  266.         mov    cSecond,dx        ; set second within minute
  267.         xor    ah,ah
  268.         mov    cMinute,ax        ; set minute within hour
  269.  
  270.         pop    dx            ; restore seconds since
  271.         pop    ax            ;   year 1900
  272.         shr    dx,1            ; too big for 16 bits...
  273.         rcr    ax,1
  274.         div    m12hour         ; calculate days since 1900
  275.         inc    ax
  276.         xor    dx,dx            ; calculate weeks since 1900
  277.         div    m7
  278.         mov    cWday,dx        ; set weekday
  279.         pop    si
  280.         ret
  281. DateTimeCalc    endp
  282.  
  283.